package com.smcaiot.jfttask.north.convert;

import com.smcaiot.jfttask.domain.Task;
import com.smcaiot.jfttask.domain.TaskBatch;
import com.smcaiot.jfttask.north.message.AddTaskRequest;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * @Author: cz
 * @Date: 2023/9/27
 * @Description:
 */
@Mapper
public interface AddTaskRequestConvert {
    AddTaskRequestConvert INSTANCE = Mappers.getMapper(AddTaskRequestConvert.class);

    @Mapping(target = "taskId", expression = "java(com.smcaiot.jfttask.domain.TaskId.from(request.getTaskId()))")
    @Mapping(target = "taskReceivers", expression = "java(com.smcaiot.jfttask.north.message.AddTaskRequest.AddTaskReceiver.to(request.getTaskSettingReceiverList()))")
    @Mapping(target = "taskCycle", expression = "java(new com.smcaiot.jfttask.domain.TaskCycle(request.getCycleLength()))")
    Task to(AddTaskRequest request);

    @Mapping(target = "taskId", expression = "java(com.smcaiot.jfttask.domain.TaskId.from(request.getTaskId()))")
    TaskBatch toTaskBatch(AddTaskRequest request);
}
